package com.xoa.service.trainingPlan.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.xoa.dao.common.SysCodeMapper;
import com.xoa.dao.department.DepartmentMapper;
import com.xoa.dao.trainingPlan.EduTrainingPlanMapper;
import com.xoa.dao.users.UsersMapper;
import com.xoa.model.common.SysCode;
import com.xoa.model.department.Department;
import com.xoa.model.sms.SmsBody;
import com.xoa.model.trainingPlan.EduTrainingPlan;
import com.xoa.model.users.Users;
import com.xoa.service.ThreadSerivice.ThreadService;
import com.xoa.service.trainingPlan.IEduTrainingPlanService;
import com.xoa.service.sms.SmsService;
import com.xoa.service.users.UsersService;
import com.xoa.util.AjaxJson;
import com.xoa.util.CookiesUtil;
import com.xoa.util.DateFormatUtils;
import com.xoa.util.ToJson;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.dataSource.ContextHolder;
import com.xoa.util.page.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.*;

/**
 * <p>
 * 培训计划 服务实现类
 * </p>
 *
 * @author ZLF
 * @since 2017-09-07
 */
@Service
public class EduTrainingPlanServiceImpl extends ServiceImpl<EduTrainingPlanMapper, EduTrainingPlan> implements IEduTrainingPlanService {
    @Autowired
    EduTrainingPlanMapper eduTrainingPlanMapper;
    @Autowired
    DepartmentMapper eduDepartmentMapper;

    @Resource
    UsersService usersService;
    @Resource
    UsersMapper usersMapper;

    @Resource
    private SysCodeMapper sysCodeMapper;
    @Resource
    private SmsService smsService;
    @Autowired
    ThreadService threadService;
    @Resource
    ThreadPoolTaskExecutor threadPoolTaskExecutor;

    public ToJson<EduTrainingPlan> getHrtailDetail(Integer planId){
        ToJson<EduTrainingPlan> json =new ToJson<EduTrainingPlan>();
        try {
            EduTrainingPlan traindetailById = eduTrainingPlanMapper.getTraindetailById(planId);

            //主办部门
            String sponsoringDepartment = traindetailById.getSponsoringDepartment();
            if(sponsoringDepartment!=null){
                sponsoringDepartment = sponsoringDepartment.substring(0, sponsoringDepartment.length() - 1);
                Department eduDepartmentWithBLOBs = eduDepartmentMapper.getDeptById(Integer.valueOf(sponsoringDepartment));
                if(eduDepartmentWithBLOBs!=null){
                    traindetailById.setSponsoringDepartmentName(eduDepartmentWithBLOBs.getDeptName());
                }else{
                    traindetailById.setSponsoringDepartmentName("");
                }
            }

            //负责人
            String chargePerson = traindetailById.getChargePerson();
           if(chargePerson!=null){
               chargePerson=chargePerson.substring(0, chargePerson.length() - 1);
               StringBuffer stringBuffer =new StringBuffer();
               if(chargePerson.split(",").length>1){
                  String []str=chargePerson.split(",");
                  for(String s:str){
                      Users byuserId = usersMapper.getUserId(s);
                      if(byuserId!=null){
                          stringBuffer.append(byuserId.getUserName()+",");
                      }
                  }
               }
               else{
                   Users byuserId = usersMapper.getUserId(chargePerson);
               if(byuserId!=null){
                   stringBuffer.append(byuserId.getUserName()+",");
               }else{
                   traindetailById.setChargePersonName("");
               }
               }
               traindetailById.setChargePersonName(stringBuffer.toString());
           }

            //审批人
            String assessingOfficer = traindetailById.getAssessingOfficer();
           if(assessingOfficer!=null){
               assessingOfficer = assessingOfficer.substring(0, assessingOfficer.length() - 1);
               Users byuserId3 = usersMapper.getUserId(assessingOfficer);
               if(byuserId3!=null){
                   traindetailById.setAssessingOfficerName(byuserId3.getUserName());
               }else{
                   traindetailById.setAssessingOfficerName("");
               }
           }

            //参与培训部门
            StringBuffer sb =new StringBuffer();
            String joinDept = traindetailById.getJoinDept();
            if(joinDept!=null && !"".equals(joinDept)){
                String[] split = joinDept.split(",");
                for(String s:split){
                    Department eduDepartmentWithBLOBs1 = eduDepartmentMapper.getDeptById(Integer.valueOf(s));
                    if(eduDepartmentWithBLOBs1!=null){
                        sb.append(eduDepartmentWithBLOBs1.getDeptName()+",");
                    }
                }
            }
            traindetailById.setJoinDeptName(sb.toString());
            //参与培训人员
            StringBuffer sbUser =new StringBuffer();
            String joinPerson = traindetailById.getJoinPerson();
            if(joinPerson!=null && !"".equals(joinPerson)){
                String[] split = joinPerson.split(",");
                for(String s:split){
                    Users byuserId2 = usersMapper.getUserId(s);
                    if(byuserId2!=null){
                        sbUser.append(byuserId2.getUserName()+",");
                    }
                }
            }
            traindetailById.setJoinPersonName(sbUser.toString());
            //处理部分字段
            traindetailById.setAssessingStatuName("");
            traindetailById.setChannelName("");
            traindetailById.setCourseTypesName("");
            if(traindetailById.getAssessingStatus()!=null){
            if(traindetailById.getAssessingStatus()==0){
                traindetailById.setAssessingStatuName("待审批");
            }
            else if(traindetailById.getAssessingStatus()==1){
                traindetailById.setAssessingStatuName("已批准");
            }
            else{
                traindetailById.setAssessingStatuName("已拒绝");
            }
            }
            if(traindetailById.getChannel()!=null){
            if(traindetailById.getChannel().equals("0")){
                traindetailById.setChannelName("内部培训");
            }else if(traindetailById.getChannel().equals("1")){
                traindetailById.setChannelName("渠道培训");
            }else{
                traindetailById.setChannelName("");
            }
            }
            if(traindetailById.getCourseTypes()!=null){
            if(traindetailById.getCourseTypes().equals("1")){
             traindetailById.setCourseTypesName("面授");
            }
            else if(traindetailById.getCourseTypes().equals("2")){
                traindetailById.setCourseTypesName("函授");
            }
            else{
                traindetailById.setCourseTypesName("其他");
            }
            }
            json.setFlag(0);
            json.setObject(traindetailById);
            json.setMsg("ok");
        } catch (Exception e) {
            json.setMsg("err");
            json.setFlag(1);
            e.printStackTrace();
        }
        return json;
    }



    public AjaxJson getAll(HttpServletRequest request,Integer page,Integer pageSize,boolean useFlag){
        AjaxJson ajaxJson =new AjaxJson();
        //分页分装
        PageParams pageParams = new PageParams();
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        pageParams.setUseFlag(useFlag);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("page", pageParams);

        //得到所有的培训计划
        try {
            List<EduTrainingPlan> allEduTail = eduTrainingPlanMapper.getAll(map);
            for(EduTrainingPlan eduTrainingPlan:allEduTail){
                if(eduTrainingPlan.getAssessingStatus()!=null){
                    if(eduTrainingPlan.getAssessingStatus()==0){
                        eduTrainingPlan.setAssessingStatuName("待审批");
                    }
                    else if(eduTrainingPlan.getAssessingStatus()==1){
                        eduTrainingPlan.setAssessingStatuName("已批准");
                    }
                    else{
                        eduTrainingPlan.setAssessingStatuName("已拒绝");
                    }
                }
                if(eduTrainingPlan.getChannel()!=null){
                    if(eduTrainingPlan.getChannel().equals("0")){
                        eduTrainingPlan.setChannelName("内部培训");
                    }else if(eduTrainingPlan.getChannel().equals("1")){
                        eduTrainingPlan.setChannelName("渠道培训");
                    }else{
                        eduTrainingPlan.setChannelName("");
                    }
                }
                if(eduTrainingPlan.getCourseTypes()!=null){
                    if(eduTrainingPlan.getCourseTypes().equals("1")){
                        eduTrainingPlan.setCourseTypesName("面授");
                    }
                    else if(eduTrainingPlan.getCourseTypes().equals("2")){
                        eduTrainingPlan.setCourseTypesName("函授");
                    }
                    else{
                        eduTrainingPlan.setCourseTypesName("其他");
                    }
                }
            }
            int count = eduTrainingPlanMapper.getCount();
            ajaxJson.setTotleNum(count);
            ajaxJson.setFlag(true);
            ajaxJson.setMsg("ok");
            ajaxJson.setObj(allEduTail);
        } catch (Exception e) {
            ajaxJson.setFlag(false);
            ajaxJson.setMsg("err");
            e.printStackTrace();
        }
        return ajaxJson;
    }

    @Override
    public AjaxJson editTrain(EduTrainingPlan eduTrainingPlan) {
        AjaxJson ajaxJson =new AjaxJson();
        ajaxJson.setFlag(false);
        try {
            eduTrainingPlanMapper.editTrain(eduTrainingPlan);
            ajaxJson.setMsg("ok");
            ajaxJson.setFlag(true);
        } catch (Exception e) {
            ajaxJson.setMsg(e.getMessage());
            ajaxJson.setFlag(false);
            e.printStackTrace();
        }
        return ajaxJson;
    }

    @Override
    public AjaxJson deleteTrainObjects(String[] planIds) {
        AjaxJson ajaxJson =new AjaxJson();
        ajaxJson.setFlag(false);
        try {
            eduTrainingPlanMapper.deleteObject(planIds);
            ajaxJson.setMsg("ok");
            ajaxJson.setFlag(true);
        } catch (Exception e) {
            ajaxJson.setMsg(e.getMessage());
            ajaxJson.setFlag(false);
            e.printStackTrace();
        }
        return ajaxJson;
    }

    @Override
    public AjaxJson deleteTrainById(String planId) {
        AjaxJson ajaxJson =new AjaxJson();
        ajaxJson.setFlag(false);
        try {
            eduTrainingPlanMapper.deleteObjectById(planId);
            ajaxJson.setMsg("ok");
            ajaxJson.setFlag(true);
        } catch (Exception e) {
            ajaxJson.setMsg(e.getMessage());
            ajaxJson.setFlag(false);
            e.printStackTrace();
        }
        return ajaxJson;
    }

    @Override
    public AjaxJson addTrain(HttpServletRequest request,EduTrainingPlan eduTrainingPlan,String remind) {
        AjaxJson ajaxJson =new AjaxJson();
        ajaxJson.setFlag(false);
        Date date =new Date();
        String tuisong=request.getParameter("tuisong");
        try {
            //从session中获取当前登录人的信息
            Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
            Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
             eduTrainingPlan.setCreateUserId(users.getUserId());
             eduTrainingPlan.setCreateDeptId(users.getDeptId());
             eduTrainingPlan.setAddTime(date);
            int count = eduTrainingPlanMapper.addTrain(eduTrainingPlan);
            if (count > 0) {
                addAffairs(eduTrainingPlan,request);
            }
            ajaxJson.setMsg("ok");
            ajaxJson.setFlag(true);
        } catch (Exception e) {
            ajaxJson.setMsg(e.getMessage());
            ajaxJson.setFlag(false);
            e.printStackTrace();
        }
        return ajaxJson;
    }

    /**
     * 给培训计划添加提醒事务
     * @param eduTrainingPlan
     */
    @Async
    public void addAffairs(final EduTrainingPlan eduTrainingPlan, HttpServletRequest request) {
        final String sqlType = (String) request.getSession().getAttribute("loginDateSouse");
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        final String userName = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionCookie).getUserName();
        this.threadPoolTaskExecutor.execute(new Runnable() {
            @Override
            public void run() {
                ContextHolder.setConsumerType("xoa" + sqlType);
                SmsBody smsBody = new SmsBody();
                //创建人
                smsBody.setFromId(eduTrainingPlan.getCreateUserId());
                //参与人和审批人和负责人
                StringBuffer toUserId = new StringBuffer();
                if(!StringUtils.checkNull(eduTrainingPlan.getAssessingOfficer())){
                    toUserId.append(eduTrainingPlan.getAssessingOfficer()).append(",");
                }
                if(!StringUtils.checkNull(eduTrainingPlan.getJoinPerson())){
                    toUserId.append(eduTrainingPlan.getJoinPerson()).append(",");
                }
                if(!StringUtils.checkNull(eduTrainingPlan.getChargePerson())){
                    toUserId.append(eduTrainingPlan.getChargePerson()).append(",");
                }
                //部门人员（参与培训部门和主办部门）
                if(!StringUtils.checkNull(eduTrainingPlan.getJoinDept())){
                    String[] str = eduTrainingPlan.getJoinDept().split(",");
                    for(int i=0;i<str.length;i++){
                       List<Users> users = usersMapper.getUsersByPId(Integer.valueOf(str[i]));
                       for (Users users1 :users){
                           toUserId.append(users1.getUserId()).append(",");
                       }
                    }
                }

                //主办部门
                if(!StringUtils.checkNull(eduTrainingPlan.getSponsoringDepartment())){
                    String[] str = eduTrainingPlan.getSponsoringDepartment().split(",");
                    for(int i=0;i<str.length;i++){
                        List<Users> users = usersMapper.getUsersByPId(Integer.valueOf(str[i]));
                        for (Users users1 :users){
                            toUserId.append(users1.getUserId()).append(",");
                        }
                    }
                }

                //去重
                if(!StringUtils.checkNull(toUserId.toString())){
                    String[] userArr=toUserId.toString().split(",");
                    List<String> list = new ArrayList<>();
                    list.add(userArr[0]);
                    for(int i=1;i<userArr.length;i++){
                        if(list.toString().indexOf(userArr[i]) == -1){
                            list.add(userArr[i]);
                        }
                    }
                    toUserId=new StringBuffer();
                    for(String temp:list){
                        toUserId.append(temp).append(",");
                    }
                }
                Integer sendTime=0;
                if(eduTrainingPlan.getAddTime()!=null){
                    try {
                        sendTime= DateFormatUtils.getNowDateTime(DateFormatUtils.formatDate(eduTrainingPlan.getAddTime()));
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
                smsBody.setSendTime(sendTime);
                SysCode sysCode=new SysCode();
                sysCode.setCodeName("新建培训计划");
                sysCode.setParentNo("SMS_REMIND");
                if(!StringUtils.checkNull(eduTrainingPlan.getAttachmentId())&&!StringUtils.checkNull(eduTrainingPlan.getAttachmentName())){
                    smsBody.setIsAttach("1");
                }
                if(sysCodeMapper.getCodeNoByNameAndParentNo(sysCode)!=null){
                    smsBody.setSmsType(sysCodeMapper.getCodeNoByNameAndParentNo(sysCode).getCodeNo());
                }

                smsBody.setRemindUrl("eduTrainPlan/goDetail?planId="+eduTrainingPlan.getPlanId());
                String title = userName + "您有新的培训计划！";
                smsBody.setContent("请查看培训计划！课程名："+eduTrainingPlan.getPlanName());

                smsBody.setEditFlag("1");
                String context=eduTrainingPlan.getContent();
                smsService.saveSms(smsBody, toUserId.toString(), "1", "1", title, context, sqlType);
            }
        });

    }

    @Override
    public AjaxJson queryTrain(Integer page,Integer pageSize,boolean useFlag,EduTrainingPlan eduTrainingPlan) {
        AjaxJson ajaxJson =new AjaxJson();
        ajaxJson.setFlag(false);
        try {
            //分页分装
            PageParams pageParams = new PageParams();
            pageParams.setPage(page);
            pageParams.setPageSize(pageSize);
            pageParams.setUseFlag(useFlag);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("page", pageParams);
            map.put("eduTrainingPlan",eduTrainingPlan);
            List<EduTrainingPlan> eduTrainingPlans = eduTrainingPlanMapper.queryTrain(map);
            for(EduTrainingPlan eduTrainingPlan_1:eduTrainingPlans){
                //处理部分字段
                eduTrainingPlan_1.setAssessingStatuName("");
                eduTrainingPlan_1.setChannelName("");
                eduTrainingPlan_1.setCourseTypesName("");
                if(eduTrainingPlan_1.getAssessingStatus()!=null){
                    if(eduTrainingPlan_1.getAssessingStatus()==0){
                        eduTrainingPlan_1.setAssessingStatuName("待审批");
                    }
                    else if(eduTrainingPlan_1.getAssessingStatus()==1){
                        eduTrainingPlan_1.setAssessingStatuName("已批准");
                    }
                    else{
                        eduTrainingPlan_1.setAssessingStatuName("已拒绝");
                    }
                }
                if(eduTrainingPlan_1.getChannel()!=null){
                    if(eduTrainingPlan_1.getChannel().equals("0")){
                        eduTrainingPlan_1.setChannelName("内部培训");
                    }else if(eduTrainingPlan_1.getChannel().equals("1")){
                        eduTrainingPlan_1.setChannelName("渠道培训");
                    }else{
                        eduTrainingPlan_1.setChannelName("");
                    }
                }
                if(eduTrainingPlan_1.getCourseTypes()!=null){
                    if(eduTrainingPlan_1.getCourseTypes().equals("1")){
                        eduTrainingPlan_1.setCourseTypesName("面授");
                    }
                    else if(eduTrainingPlan_1.getCourseTypes().equals("2")){
                        eduTrainingPlan_1.setCourseTypesName("函授");
                    }
                    else{
                        eduTrainingPlan_1.setCourseTypesName("其他");
                    }
                }
            }
            ajaxJson.setObj(eduTrainingPlans);
            ajaxJson.setMsg("ok");
            ajaxJson.setFlag(true);
        } catch (Exception e) {
            ajaxJson.setMsg(e.getMessage());
            ajaxJson.setFlag(false);
            e.printStackTrace();
        }
        return ajaxJson;
    }

    @Override
    public AjaxJson getEduTrainByStatus(HttpServletRequest request,String assessingStatus) {
        AjaxJson ajaxJson =new AjaxJson();
        ajaxJson.setFlag(false);
        try {
            //从session中获取当前登录人的信息
            Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
            Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
            String userId = users.getUserId();
            Map<String,Object> map =new HashMap<String,Object>();
            map.put("userId",userId);
            map.put("assessingStatus",assessingStatus);
            List<EduTrainingPlan> eduTrainByStatus = eduTrainingPlanMapper.getEduTrainByStatus(map);
            for(EduTrainingPlan eduTrainingPlan:eduTrainByStatus){
                //处理部分字段
                eduTrainingPlan.setAssessingStatuName("");
                eduTrainingPlan.setChannelName("");
                eduTrainingPlan.setCourseTypesName("");
                if(eduTrainingPlan.getAssessingStatus()!=null){
                    if(eduTrainingPlan.getAssessingStatus()==0){
                        eduTrainingPlan.setAssessingStatuName("待审批");
                    }
                    else if(eduTrainingPlan.getAssessingStatus()==1){
                        eduTrainingPlan.setAssessingStatuName("已批准");
                    }
                    else{
                        eduTrainingPlan.setAssessingStatuName("已拒绝");
                    }
                }
                if(eduTrainingPlan.getChannel()!=null){
                    if(eduTrainingPlan.getChannel().equals("0")){
                        eduTrainingPlan.setChannelName("内部培训");
                    }else if(eduTrainingPlan.getChannel().equals("1")){
                        eduTrainingPlan.setChannelName("渠道培训");
                    }else{
                        eduTrainingPlan.setChannelName("");
                    }
                }
                if(eduTrainingPlan.getCourseTypes()!=null){
                    if(eduTrainingPlan.getCourseTypes().equals("1")){
                        eduTrainingPlan.setCourseTypesName("面授");
                    }
                    else if(eduTrainingPlan.getCourseTypes().equals("2")){
                        eduTrainingPlan.setCourseTypesName("函授");
                    }
                    else{
                        eduTrainingPlan.setCourseTypesName("其他");
                    }
                }
            }
            ajaxJson.setObj(eduTrainByStatus);
            ajaxJson.setMsg("ok");
            ajaxJson.setFlag(true);
        } catch (Exception e) {
            ajaxJson.setMsg(e.getMessage());
            ajaxJson.setFlag(false);
            e.printStackTrace();
        }
        return ajaxJson;
    }

    @Override
    public AjaxJson editEduTrainByStatus(EduTrainingPlan eduTrainingPlan) {
        AjaxJson ajaxJson =new AjaxJson();
        ajaxJson.setFlag(false);
        //设置审批时间为当前时间
        Date date =new Date();
        eduTrainingPlan.setAssessingTime(date);
        try {
            eduTrainingPlanMapper.editEduTrainByStatus(eduTrainingPlan);
            ajaxJson.setMsg("ok");
            ajaxJson.setFlag(true);
        } catch (Exception e) {
            ajaxJson.setMsg(e.getMessage());
            ajaxJson.setFlag(false);
            e.printStackTrace();
        }
        return ajaxJson;
    }

    @Override
    public AjaxJson QueryPlan(EduTrainingPlan eduTrainingPlan,String startTime,String endTime) {
        AjaxJson ajaxJson =new AjaxJson();
        try {
            Map<String,Object> map =new HashMap<String,Object>();
            map.put("eduTrainingPlan",eduTrainingPlan);
            map.put("startTime",startTime);
            map.put("endTime",endTime);
            List<EduTrainingPlan> eduTrainingPlans = eduTrainingPlanMapper.QueryPlan(map);
            for(EduTrainingPlan eduTrainingPlan_1:eduTrainingPlans){
                //处理部分字段
                eduTrainingPlan_1.setAssessingStatuName("");
                eduTrainingPlan_1.setChannelName("");
                eduTrainingPlan_1.setCourseTypesName("");
                if(eduTrainingPlan_1.getAssessingStatus()!=null){
                    if(eduTrainingPlan_1.getAssessingStatus()==0){
                        eduTrainingPlan_1.setAssessingStatuName("待审批");
                    }
                    else if(eduTrainingPlan_1.getAssessingStatus()==1){
                        eduTrainingPlan_1.setAssessingStatuName("已批准");
                    }
                    else{
                        eduTrainingPlan_1.setAssessingStatuName("已拒绝");
                    }
                }
                if(eduTrainingPlan_1.getChannel()!=null){
                    if(eduTrainingPlan_1.getChannel().equals("0")){
                        eduTrainingPlan_1.setChannelName("内部培训");
                    }else if(eduTrainingPlan_1.getChannel().equals("1")){
                        eduTrainingPlan_1.setChannelName("渠道培训");
                    }else{
                        eduTrainingPlan_1.setChannelName("");
                    }
                }
                if(eduTrainingPlan_1.getCourseTypes()!=null){
                    if(eduTrainingPlan_1.getCourseTypes().equals("1")){
                        eduTrainingPlan_1.setCourseTypesName("面授");
                    }
                    else if(eduTrainingPlan_1.getCourseTypes().equals("2")){
                        eduTrainingPlan_1.setCourseTypesName("函授");
                    }
                    else{
                        eduTrainingPlan_1.setCourseTypesName("其他");
                    }
                }
            }
            ajaxJson.setMsg("ok");
            ajaxJson.setFlag(true);
            ajaxJson.setObj(eduTrainingPlans);
        } catch (Exception e) {
            ajaxJson.setMsg(e.getMessage());
            ajaxJson.setFlag(false);
            e.printStackTrace();
        }
        return ajaxJson;
    }

    @Override
    public AjaxJson QueryPlanStatus(EduTrainingPlan eduTrainingPlan, String startTime, String endTime,HttpServletRequest request) {
        AjaxJson ajaxJson =new AjaxJson();
        try {
            Map<String,Object> map =new HashMap<String,Object>();
            //从session中获取当前登录人的信息
            Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
            Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
            String userId =users.getUserId();
            map.put("eduTrainingPlan",eduTrainingPlan);
            map.put("startTime",startTime);
            map.put("endTime",endTime);
            map.put("userId",userId);
            List<EduTrainingPlan> eduTrainingPlans = eduTrainingPlanMapper.QueryPlanStatus(map);
            for(EduTrainingPlan eduTrainingPlan_1:eduTrainingPlans){
                //处理部分字段
                eduTrainingPlan_1.setAssessingStatuName("");
                eduTrainingPlan_1.setChannelName("");
                eduTrainingPlan_1.setCourseTypesName("");
                if(eduTrainingPlan_1.getAssessingStatus()!=null){
                    if(eduTrainingPlan_1.getAssessingStatus()==0){
                        eduTrainingPlan_1.setAssessingStatuName("待审批");
                    }
                    else if(eduTrainingPlan_1.getAssessingStatus()==1){
                        eduTrainingPlan_1.setAssessingStatuName("已批准");
                    }
                    else{
                        eduTrainingPlan_1.setAssessingStatuName("已拒绝");
                    }
                }
                if(eduTrainingPlan_1.getChannel()!=null){
                    if(eduTrainingPlan_1.getChannel().equals("0")){
                        eduTrainingPlan_1.setChannelName("内部培训");
                    }else if(eduTrainingPlan_1.getChannel().equals("1")){
                        eduTrainingPlan_1.setChannelName("渠道培训");
                    }else{
                        eduTrainingPlan_1.setChannelName("");
                    }
                }
                if(eduTrainingPlan_1.getCourseTypes()!=null){
                    if(eduTrainingPlan_1.getCourseTypes().equals("1")){
                        eduTrainingPlan_1.setCourseTypesName("面授");
                    }
                    else if(eduTrainingPlan_1.getCourseTypes().equals("2")){
                        eduTrainingPlan_1.setCourseTypesName("函授");
                    }
                    else{
                        eduTrainingPlan_1.setCourseTypesName("其他");
                    }
                }
            }
            ajaxJson.setMsg("ok");
            ajaxJson.setFlag(true);
            ajaxJson.setObj(eduTrainingPlans);
        } catch (Exception e) {
            ajaxJson.setMsg(e.getMessage());
            ajaxJson.setFlag(false);
            e.printStackTrace();
        }
        return ajaxJson;
    }

    @Override
    public AjaxJson getMinePlanByStatus(HttpServletRequest request, String assessingStatus) {
        AjaxJson ajaxJson =new AjaxJson();
        ajaxJson.setFlag(false);
        try {
            //从session中获取当前登录人的信息
            Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
            Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
            String userId = users.getUserId();
            Map<String,Object> map =new HashMap<String,Object>();
            map.put("userId",userId);
            map.put("assessingStatus",assessingStatus);
            List<EduTrainingPlan> eduTrainByStatus = eduTrainingPlanMapper.getMinePlanByStatus(map);
            for(EduTrainingPlan eduTrainingPlan:eduTrainByStatus){
                //处理部分字段
                eduTrainingPlan.setAssessingStatuName("");
                eduTrainingPlan.setChannelName("");
                eduTrainingPlan.setCourseTypesName("");
                if(eduTrainingPlan.getAssessingStatus()!=null){
                    if(eduTrainingPlan.getAssessingStatus()==0){
                        eduTrainingPlan.setAssessingStatuName("待审批");
                    }
                    else if(eduTrainingPlan.getAssessingStatus()==1){
                        eduTrainingPlan.setAssessingStatuName("已批准");
                    }
                    else{
                        eduTrainingPlan.setAssessingStatuName("已拒绝");
                    }
                }
                if(eduTrainingPlan.getChannel()!=null){
                    if(eduTrainingPlan.getChannel().equals("0")){
                        eduTrainingPlan.setChannelName("内部培训");
                    }else if(eduTrainingPlan.getChannel().equals("1")){
                        eduTrainingPlan.setChannelName("渠道培训");
                    }else{
                        eduTrainingPlan.setChannelName("");
                    }
                }
                if(eduTrainingPlan.getCourseTypes()!=null){
                    if(eduTrainingPlan.getCourseTypes().equals("1")){
                        eduTrainingPlan.setCourseTypesName("面授");
                    }
                    else if(eduTrainingPlan.getCourseTypes().equals("2")){
                        eduTrainingPlan.setCourseTypesName("函授");
                    }
                    else{
                        eduTrainingPlan.setCourseTypesName("其他");
                    }
                }
            }
            ajaxJson.setObj(eduTrainByStatus);
            ajaxJson.setMsg("ok");
            ajaxJson.setFlag(true);
        } catch (Exception e) {
            ajaxJson.setMsg(e.getMessage());
            ajaxJson.setFlag(false);
            e.printStackTrace();
        }
        return ajaxJson;
    }

    @Override
    public AjaxJson getAllPlan() {
        AjaxJson ajaxJson =new AjaxJson();
        ajaxJson.setFlag(false);
        try {
            List<EduTrainingPlan> allPlan = eduTrainingPlanMapper.getAllPlan();
            ajaxJson.setObj(allPlan);
            ajaxJson.setMsg("ok");
            ajaxJson.setFlag(true);
        } catch (Exception e) {
            ajaxJson.setMsg(e.getMessage());
            ajaxJson.setFlag(false);
            e.printStackTrace();
        }
        return ajaxJson;
    }

    @Override
    public AjaxJson getAllPlanTrue() {
        AjaxJson ajaxJson =new AjaxJson();
        ajaxJson.setFlag(false);
        try {
            List<EduTrainingPlan> allPlan = eduTrainingPlanMapper.getAllPlanTrue();
            ajaxJson.setObj(allPlan);
            ajaxJson.setMsg("ok");
            ajaxJson.setFlag(true);
        } catch (Exception e) {
            ajaxJson.setMsg(e.getMessage());
            ajaxJson.setFlag(false);
            e.printStackTrace();
        }
        return ajaxJson;
    }
}
